<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>供应商报关报检业务管理-驳回</title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript" src="<s:url value="/js/ajaxutil.js"/>"></script>
</head>
<script type="text/javascript">
    var bstate = "${param.declaraState }";
    var formSetting = {
        title: "查询报关报检业务信息",
        module: 'query',
        columns: [{
            name: "businessId",
            label: "业务编号"
        },
// 		{
// 			name : "state",
// 			label : "业务状态"
// 			type:"dropdown",
// 			dropdownType:"ajax",
// 			url:"../base/dropdown-declarationState",
// 			op:"eq",
// 			minLength:0
// 		},
            {
                name: "container_no",
                label: "集装箱号"
            }, {
                name: "contract_no",
                label: "合同协议号"
            }, {
                name: "confirmTime",
                label: "业务提交时间从",
                type: "date",
                op: "ge"
            }, {
                name: "confirmTime",
                label: "到",
                type: "date",
                op: "le"
            }, {
                name: "company_co",
                label: "经营单位",
                type: "dropdown",
                dropdownType: "ajax",
                url: "companyqp-findCompanyByCode?tdateaa=" + timeNum(),
                op: "eq",
                minLength: 0
            }, {
                name: "shipper.company",
                label: "实际托运人"
            }],
        buttons: {
            custom: [
// 				{
// 					id : "updatebtn-1",
// 					value : "业务流转",
// 					click : function() {
// 						var id = $("#declarationsDataGrid").jqGrid("getGridParam",
// 						"selrow");
// 						if(id) {
// 							var ret = $("#declarationsDataGrid").jqGrid('getRowData',id);
// 							var iddata = "id=" + ret.id;
// 							$.ajax({
// 								cache: false,
// 								url : "declaration-checkValidatePass",
// 								dataType : "json",
// 								data : iddata,
// 								success : function(data) {
// 									if($.parseJSON(data.msg).state==1) {
// 										jw.confirm("确定要该业务进行流转?",function(){
// 											jw.dialog({iframe:'bizFlow-supChoiceList?sup_type=D&id='+id,width:500, height:200});
// 										},
// 										function(){return;});
// 									}
// 									else if($.parseJSON(data.msg).state==0) {
// 										jw.alert("只有处于审核状态的业务才可以进行业务流转操作。");
// 									}
// 									else {
// 										jw.alert($.parseJSON(data.msg).msg);
// 									}
// 								}
// 							});
// 						} else {
// 							jw.alert("请点击需要操作的数据!");
// 						}
// 					}
// 				},
                {
                    id: "updatebtn0",
                    value: "查看详细",
                    click: function () {
                        /* var id = $("#declarationsDataGrid").jqGrid("getGridParam",
                         "selrow");
                         if(id) {
                         window.location.href="declaration-findForSupToValidate?id="+id;
                         } else {
                         jw.alert("请点击需要操作的数据!");
                         } */
                        var selectedRowId = $("#declarationsDataGrid").getGridParam("selrow");
                        if (selectedRowId) {
                            var selectedRow = $("#declarationsDataGrid").getRowData(selectedRowId);
                            if (selectedRow.state == "草稿状态") {
                                //selectedRow.busiId
                                location.href =
                                        "business-updateSingle?id=" + selectedRow.id
                                        + "&singleType=D";
                            } else {
                                ajaxLoader.ajaxPost(
                                        '../datalock/onUnlock?opaId=VDBS&bidId=' + selectedRow.id,
                                        {}, function (data) {
                                            if (!data.result) {
                                                jw.alert(data.errmsg);
                                            }
                                            if ("200" == data.errcode) {
                                                location.href =
                                                        "business-updateSingle?id=" + selectedRow.id
                                                        + "&singleType=D&identification=list";
                                            }
                                            else {
                                                jw.alert(data.errmsg);
                                            }
                                        });
                            }
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "exportExcel",
                    value: "导出数据",
                    click: function () {
                        var businessId = $("#form_in_control_1").val();
                        var state = bstate.substr(0, 4);
                        if (state == "DS02") {
                            state = "('DS02','DS04','DS05','DS06','DS07','DS08','DS09','DS10')";
                        } else if (state == "DS01") {
                            state = "('DS01')";
                        } else if (state == "DS03") {
                            state = "('DS03')";
                        }
                        var container_no = $("#form_in_control_3").val();
                        var contract_no = $("#form_in_control_4").val();
                        var confirm_time_start = $("#form_in_control_5").val();
                        if (confirm_time_start != "") {
                            confirm_time_start = confirm_time_start + " 00:00:00";
                        }
                        var confirm_time_end = $("#form_in_control_6").val();
                        if (confirm_time_end != "") {
                            confirm_time_end = confirm_time_end + " 23:59:59";
                        }
                        var company_name = $("#form_in_control_7").val();
                        var shipper_name = $("#form_in_control_8").val();
                        var url = "http://localhost:8075/WebReport/ReportServer?reportlet=supDeclarationList.cpt&businessId="
                                  // 	var url = "http://192.168.0.4:7080/report/ReportServer?reportlet=gtimp/supDeclarationList.cpt&businessId="
                                  + businessId
                                  + "&state="
                                  + state
                                  + "&container_no="
                                  + container_no
                                  + "&contract_no="
                                  + contract_no
                                  + "&company_name="
                                  + company_name
                                  + "&shipper_name="
                                  + shipper_name
                                  + "&confirm_time_start="
                                  + confirm_time_start
                                  + "&confirm_time_end="
                                  + confirm_time_end;//本机
                        window.open(url);
                    }
                }
            ]
        },
        grid: {
            id: "declarationsDataGrid",
            title: "查询结果",
            url: "declaration-findListForSupToValidate",
            //multiselect : true,
            /* postData : {
             "pid" : pid
             }, */
            postData: {
                "declaraState": bstate
            },
            colModel: [{
                index: "ID",
                name: "id",
                hidden: true
            }, {
                index: "businessId",
                name: "businessId",
                label: "业务编号"
            }, {
                index: "work_no",
                name: "work_no",
                label: "三联单流水号"
            }, {
                index: "container_no",
                name: "container_no",
                label: "集装箱号"
            }, {
                index: "contract_no",
                name: "contract_no",
                label: "合同协议号"
            }, {
                index: "company_name",
                name: "company_name",
                label: "经营单位"
            }, {
                index: "customerNAME",
                name: "customer.name",
                label: "业务委托人",
                hidden: true
            }, {
                index: "shipper",
                name: "shipper.company",
                label: "实际托运人"
            }, {
                index: "confirmTime",
                name: "confirmTime",
                label: "业务提交时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "validateState",
                name: "decState",
                label: "业务状态"
            }, {
                index: "validator",
                name: "validator.name",
                label: "审核人"
            }, {
                index: "validateTime",
                name: "validateTime",
                label: "审核时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "informState",
                name: "declarationInform.confirmState",
                label: "资料寄送提醒进度",
                hidden: true
            }, {
                index: "realSupId",
                name: "realSupId",
                label: "是否来自业务流转",
                hidden: true
            }],
// 			sortname: "businessId",
            sortname: "confirmTime",
            sortorder: "desc",
            jsonReader: {
//                root: "declarations"
            },
            loadComplete: function (data) {
                var ids = $("#declarationsDataGrid").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var arrayData = $("#declarationsDataGrid").getRowData(ids[i]);
                    if ($(arrayData).attr('declarationInform.confirmState') == "0") {
                        $("#declarationsDataGrid").setCell(ids[i], "declarationInform.confirmState",
                                                           "已发送，待确认");
                    }
                    else if ($(arrayData).attr('declarationInform.confirmState') == "1") {
                        $("#declarationsDataGrid").setCell(ids[i], "declarationInform.confirmState",
                                                           "已确认接收");
                        $($("#" + arrayData.id).find("td")[8]).addClass("biz_state_finish");
                    }
                    else {
                        $("#declarationsDataGrid").setCell(ids[i], "declarationInform.confirmState",
                                                           "客户未发送");
                    }

                    if (arrayData.realSupId == "") {
                        //$("#declarationsDataGrid").setCell(ids[i], "realSupId", "待确认");
                    }
                    else {
                        var rsid = arrayData.realSupId.split(":")[0];
                        var fstate = arrayData.realSupId.split(":")[1];
                        $("#declarationsDataGrid").setCell(ids[i], "realSupId", fstate);
                    }

                    //处理合同协议号默认值
                    if ($(arrayData).attr('contract_no') == "最长20个字符") {
                        $("#declarationsDataGrid").setCell(ids[i], "contract_no", " ");
                    }

                }
            },
            ondblClickRow: function () {
                var selectedRowId = $("#declarationsDataGrid").getGridParam("selrow");
                if (selectedRowId) {
                    var selectedRow = $("#declarationsDataGrid").getRowData(selectedRowId);
                    ajaxLoader.ajaxPost('../datalock/onUnlock?opaId=VDBS&bidId=' + selectedRow.id,
                                        {},
                                        function (data) {
                                            if (!data) {
                                                jw.alert(data.errmsg);
                                            }
                                            if ("200" == data.errcode) {
                                                if (selectedRow.state == "草稿状态") {
                                                    //selectedRow.busiId
                                                    location.href =
                                                            "business-updateSingle?id="
                                                            + selectedRow.id + "&singleType=D";
                                                } else {
                                                    location.href =
                                                            "business-updateSingle?id="
                                                            + selectedRow.id
                                                            + "&singleType=D&identification=list";
                                                }
                                            }
                                            else {
                                                jw.alert(data.errmsg);
                                            }
                                        });
// 					if(selectedRow.state =="草稿状态"){
// 						//selectedRow.busiId
// 						location.href = "business-updateSingle?id="+selectedRow.id+"&singleType=D";
// 					}else{
// 						location.href = "business-updateSingle?id="+selectedRow.id+"&singleType=D&identification=list";
// 					}
                }
            }
        }
    };
    $(document).ready(function () {
        $("#declarationsDataTable").mrdForm(formSetting);
    });
</script>
<body>
<div id="declarationsDataTable"></div>
</body>
</html>
